function f=ict (coef,identifier,wrapping,mode)
%inverse curvelet transformation
%f=ict (coef,identifier)
%
%use f=ict(coef,identifier,mode) with mode according to get_fourier_mask if
%you want to apply an additional fourier window before the inverse fourier
%transformation.
%
%
%author: Sebastian Schmelcher version: 2012-07-06


%identiffier recognision
%identifier can be used to set the mode. Therefore identifier must be a
%cell with the following structure:
% {{identifier},{[bool_ct bool_ict]},{mode}}
% where bool_ict determines of mode is used during the ict mehtod
%

%%%%%%%%%%%%%%%
cut_negative_data = true;
%%%%%%%%%%%%%%%


if(nargin<2)
    identifier=coef{end}{3};
end

if(nargin<3)
    wrapping=true;
end
mode_bool=false;
if(nargin>3)
    mode_bool=true;
end

if(iscell(identifier))
   if(length(identifier)>1)
       mode_bool=identifier{2}(2);
       if(mode_bool)
           mode=identifier{3};
       end
   end
   identifier=identifier{1};
end

%imSize=size(coef{1}{1});
imSize=coef{end}{2};


printLog=1;%0=OFF,1=short info, 2=full info


num_radial=length(coef)-1;

low=coef{end}{1};
if(wrapping)
    [curvelet,~]=get_curvelet(identifier,imSize,0,0);
    if(iscell(curvelet))
        point=curvelet{2};
        shift=curvelet{3};
        sector=get_wrapp_periodization(fftshift(fft2(low)),imSize,shift,point).*curvelet{1};
        f_hat=zeros(imSize);
        f_hat(point(1):point(2),point(3):point(4))=sector;
    else
        f_hat=get_wrapp_periodization(fftshift(fft2(low)),imSize).*get_curvelet(identifier,imSize,0,0);
    end
    
else
    f_hat=fftshift(fft2(low)).*get_curvelet(identifier,imSize,0,0);
end

if(printLog==1)
    fprintf(['ict (' num2str(num_radial) '): ']);
end

for radial=1:num_radial
    if(printLog>0)
        if(printLog>1)
            fprintf(['ict: Iteration ' num2str(radial) ' of ' num2str(num_radial) '\n']);
        else
            fprintf('.');
            if(radial==num_radial)
                fprintf('\n');
            end
        end
    end
    num_angular=length(coef{radial});
    for angular=1:num_angular
        if(printLog>1)
            fprintf('.');
            if(angular==num_angular)
                fprintf('\n');
            end
        end
        if(sum(abs(coef{radial}{angular}(:)))>0)
            if(wrapping)
                [curvelet,~]=get_curvelet(identifier,imSize,radial,angular);
                
                if(iscell(curvelet))
                    point=curvelet{2};
                    shift=curvelet{3};
                    sector=get_wrapp_periodization(fftshift(fft2(coef{radial}{angular})),imSize,shift,point).*curvelet{1};
                    f_hat(point(1):point(2),point(3):point(4))=f_hat(point(1):point(2),point(3):point(4))+sector;
                else
                    f_hat=f_hat+get_wrapp_periodization(fftshift(fft2(coef{radial}{angular})),imSize).*curvelet;
                end;
            else
                curvelet=get_curvelet(identifier,imSize,radial,angular);
                %curvelet=ifftshift(ifft2(curvelet));
                %f=f+coef{radial}{angular}.*curvelet;  %hier muss noch gearbeitet werden
                f_hat=f_hat+fftshift(fft2(coef{radial}{angular})).*curvelet;%.*curvelet;
            end
        end
    end
end 
 

if(mode_bool)
    f_hat=f_hat.*get_fourier_mask(mode,imSize);
end

f=real(ifft2(ifftshift(f_hat)));
f(f<0)=0;
if(cut_negative_data)

end